package com.vueperson.vueperson.t1.IO;

import java.io.*;

public class ReadAndWriteByteToFile {

    private InputStream is =null;
    private OutputStream os = null;
    public ReadAndWriteByteToFile(InputStream is,OutputStream os){
        this.is=is;
        this.os=os;
    }

    public static void test(ReadAndWriteByteToFile rw) throws IOException {

        try {
            byte[] buf = new byte[50];
            int hasRead = 0;
            while ((hasRead = rw.getIs().read(buf)) > 0) {
                rw.getOs().write(buf, 0, hasRead);
            }
            System.out.println("success");
        }catch (Exception e) {
            e.printStackTrace();
        }finally{
            rw.getIs().close();
            rw.getOs().close();
        }




    }

    public InputStream getIs() {
        return is;
    }

    public void setIs(InputStream is) {
        this.is = is;
    }

    public OutputStream getOs() {
        return os;
    }

    public void setOs(OutputStream os) {
        this.os = os;
    }

    public static void main(String[] args) throws IOException {
         InputStream is =new FileInputStream("D:/桌面/FileInputStreamTest.txt");
         OutputStream os = new FileOutputStream("D:/桌面/FileInputStreamTest2.txt");
        ReadAndWriteByteToFile rw=new ReadAndWriteByteToFile(is,os);

        rw.test(rw);
    }
}
